<?php

namespace App\Http\Services\FormBuilder\Elements;

class Address extends Field
{
    public $fillable = [
        'value'
    ];

    public function placeholder($placeholder)
    {
        $this->setAttribute('placeholder', $placeholder);

        return $this;
    }

    public function render()
    {
        $data =  $this->getControl(0);
        $data['value'] =  explode("&nbsp;",$data['value']);
        $html = view('element.address.edit_block',$data)->render();
        return $html;
    }

    public function defaultValue($value)
    {
        if (!$this->hasValue()) {
            $this->setValue($value);
        }

        return $this;
    }

    protected function hasValue()
    {
        return isset($this->attributes['value']);
    }

    public function editBlock()
    {
        return $this->render();
    }

    public function detailBlock()
    {
        $data =  $this->getControl(0);
        $class = 'col-md-12';
        $displayName = $data['display_name'];
        $value = $data['value'];

        $html = '';
        $html .= '<div class="items '.$class.'">';
        $html .= '<label class="col-3">'.$displayName.'</label>&nbsp';
        $html .= '<div class="detail col-10">'.$value.'</div>';
        $html .='</div>';

        return $html;
    }
}
